package smedi.ismedi.web.bff.controller.report;


import com.smedi.ismedi.report.api.feign.RemoteReportCheckFeignApi;
import com.smedi.ismedi.report.api.model.ReportCheck;
import com.smedi.ismedi.report.api.model.vo.ReportCheckExportVo;
import com.smedi.ismedi.web.starter.common.PaginationData;
import com.smedi.ismedi.web.starter.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RequestMapping(value = "/webbff/v1/report")
@RestController
@Api(tags = {"外部单位检查"})
public class RemoteReportCheckController {

 @Autowired
 RemoteReportCheckFeignApi remoteReportCheckFeignApi;


    @GetMapping("/test")
    @ApiOperation(value = "测试",nickname = "测试" )
   public ResponseData<String> test(){
       ResponseData<String> test = remoteReportCheckFeignApi.test();
       return test ;
     }


    @PostMapping({"/list"})
    @ApiOperation(value = "获取table列表",nickname = "获取table列表" )
    public ResponseData<PaginationData<ReportCheck>> getList(@RequestBody  ReportCheck reportCheck){

        return remoteReportCheckFeignApi.getList(reportCheck);
    }


    @ApiOperation(value = "新增",nickname = "新增" )
    @PostMapping({"/add"})
    public ResponseData<String> add(@RequestBody  ReportCheck reportCheck){
        return remoteReportCheckFeignApi.add(reportCheck);

    }
    @ApiOperation(value = "删除",nickname = "删除" )
    @GetMapping({"/delete/{ids}"})
    public ResponseData<String> delete(@PathVariable("ids") Long[] ids){
        return  remoteReportCheckFeignApi.delete(ids);

    }


    @ApiOperation(value = "编辑",nickname = "编辑" )
    @PostMapping({"/edit"})
    ResponseData<String> edit(@RequestBody ReportCheck reportCheck){
        return  remoteReportCheckFeignApi.edit(reportCheck);
    }

    @ApiOperation(value = "导出",nickname = "导出" )
    @PostMapping({"/export"})
    public void importCheck(@RequestBody ReportCheckExportVo reportCheck, HttpServletResponse response){
        ResponseData<byte[]> responseData = remoteReportCheckFeignApi.importCheck(reportCheck);
        ServletOutputStream outputStream =null;
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        try {
             outputStream = response.getOutputStream();
            outputStream.write(responseData.getData());
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

}
